import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '@/views/HomeView.vue';
import BarrageView from "@/views/BarrageView";
import FriendView from "@/views/FriendView";
import AboutView from "@/views/AboutView";
import ArticleDetailView from "@/views/ArticleDetailView";
import CateArticleListView from "@/views/CateArticleListView";
import ArticleAddView from "@/views/ArticleAddView";
import store from "@/store";
const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView
  },
  {
    path: '/barrage',
    name: 'Barrage',
    component: BarrageView
  },
  {
    path: '/friend',
    name: 'Friend',
    component: FriendView
  },
  {
    path: '/about',
    name: 'About',
    component: AboutView
  },
  {
    path: '/articleDetail',
    name: 'ArticleDetail',
    component: ArticleDetailView
  },
  {
    path: '/cateArticleList',
    name: 'CateArticleList',
    component: CateArticleListView
  },
  {
    path: '/articleAdd',
    name: 'ArticleAdd',
    component: ArticleAddView
  },
]

const router = createRouter({
  history: createWebHistory(),
  routes
})


router.beforeEach(((to, from, next) => {
  // 如果是初始化
  if(store.getters.geIsInit){
    // 初始化站点信息
    store.dispatch('updateStationInfo').then(()=>{
      // 更改 让其不是初始化
      store.dispatch('updateIsInit',false).then(()=>{
        next();
      });
    })
  }else {
    next();
  }
}))

export default router
